import {
  CHANGE_BANNER,
  CHANGE_RECOMMEND,
  FETCH_HOME_MULTIDATA
} from './contants'

import axios from 'axios'

// Banner and recommend
export const changeBannersAction = (banners) => ({
  type: CHANGE_BANNER,
  banners
})

export const changeRecommendAction = (recommends) => ({
  type: CHANGE_RECOMMEND,
  recommends
})

// redux-thunk 中定义的action函数
export const getHomeMultidataAction = dispatch => {
  axios({
    url: 'http://123.207.32.32:8000/home/multidata'
  }).then(res => {
    const data = res.data.data
    dispatch(changeBannersAction(data.banner.list))
    dispatch(changeRecommendAction(data.recommend.list))
  })
}

// redux-saga拦截的action
export const fetchHomeMultidataAction = {
  type: FETCH_HOME_MULTIDATA
}